/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import controller.layerController;
import controller.mouseController;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import type.mouseType;

/**
 *
 * @author JorgeLuis
 */
public class layerView extends javax.swing.JPanel implements MouseListener, MouseMotionListener{
    private layerController controller;
    private mouseController mouse = new mouseController();
    
    private int WIDTH   = 500;
    private int HEIGHT  = 500;

    /**
     * Creates new form layerView
     */
    public layerView() {
        this.addMouseListener(this);
        this.addMouseMotionListener(this);
        initComponents();
        this.setSize(WIDTH, HEIGHT);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setBackground(new java.awt.Color(204, 0, 0));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

    
    public void controller(layerController aThis) {
        this.controller = aThis;
        
    }

    @Override
    public void paint(Graphics grphcs) {
        super.paint(grphcs);
        Graphics2D g2 = (Graphics2D) grphcs;
        
        this.controller.drawn(g2);
        
    }
    
    
    @Override
    public void mouseClicked(MouseEvent me) {        
        mouse.setState( mouseType.mouseClicked );
        mouse.setPoint(me.getPoint());
        
        switch(me.getButton()){
            case 1: // left
                mouse.setClickLeft(true);
                break;
            case 2: // mediun
                mouse.setClickCenter(true);
                break;
            case 3: // right 
                mouse.setClickRigth(true);
                break;
        }
        controller.action(mouse);
    }

    @Override
    public void mousePressed(MouseEvent me) {
        mouse.setState( mouseType.mousePressed );
        mouse.setPoint(me.getPoint());
        
        switch(me.getButton()){
            case 1: // left
                mouse.setPressedLeft(true);
                break;
            case 2: // mediun
                mouse.setPressedCenter(true);
                break;
            case 3: // right 
                mouse.setPressedRigth(true);
                break;
        }
        controller.action(mouse);
    }

    @Override
    public void mouseReleased(MouseEvent me) {
        mouse.setState( mouseType.mouseReleased );
        mouse.setPoint(me.getPoint());
        
        switch(me.getButton()){
            case 1: // left
                mouse.setPressedLeft(false);
                break;
            case 2: // mediun
                mouse.setPressedCenter(false);
                break;
            case 3: // right 
                mouse.setPressedRigth(false);
                break;
        }
        controller.action(mouse);
    }

    @Override
    public void mouseEntered(MouseEvent me) {
        mouse.setState( mouseType.mouseEntered );
        mouse.setPoint(me.getPoint());
        controller.action(mouse);
    }

    @Override
    public void mouseExited(MouseEvent me) {
        mouse.setState( mouseType.mouseExited );
        mouse.setPoint(me.getPoint());
        controller.action(mouse);
    }

    @Override
    public void mouseDragged(MouseEvent me) {
        mouse.setState( mouseType.mouseDragged );
        mouse.setPoint(me.getPoint());
        
        switch(me.getButton()){
            case 1: // left
                mouse.setPressedLeft(true);
                break;
            case 2: // mediun
                mouse.setPressedCenter(true);
                break;
            case 3: // right 
                mouse.setPressedRigth(true);
                break;
        }
        controller.action(mouse);
    }

    @Override
    public void mouseMoved(MouseEvent me) {
        mouse.setState( mouseType.mouseMoved );
        mouse.setPoint( me.getPoint());        
        controller.action(mouse);
    }
    
}
